﻿#include <iostream>
class string 
{
public:
    string(const char *str) 
    {
        size_ = strlen(str);
        str_ = new char[size_ + 1];//+ 1是因为/0
        memcpy(str_, str, size_ + 1);
        std::cout << "拷贝完成" << std::endl;
    };
    string(const string &str) :size_(str.size_)
    {
        str_ = new char[size_ + 1];
        memcpy(str_, str.str_,size_+1);
    };
    const char* re()
    {
    if (!str_)return "";//字符串为空返回空格
    return str_;
    };
    ~string()
    {
        delete str_;
        str_ =  nullptr ;
        size_ = 0;
        std::cout<<"析构完成"<<std::endl;
    };
private:
    char *str_{ nullptr };//实际的字符串
    int size_{ 0 };
};
void testfun(string &s)
{
    std::cout << "test begin:"<<s.re() << std::endl;
};
int main()
{
    string str1("first class");
    string str2(str1);
    testfun(str2);
}

